<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\cpmjagent\controller\finance;

/**
 * Description of RechargeController
 *
 * @author SoChishun
 */
class RechargeController extends \app\cpmjagent\controller\AppbaseController {

    public function rechargelist($uid = 0) {
        $searchData=['word'=>'','date1'=>'','date2'=>''];
        if ($uid) {
            $searchData['word']=$uid;
            $list = \think\Db::table('v_finance_recharge')->where(['user_id' => $uid])->paginate(20);
        } else {
            $userid = $this->global_data['userid'];
            $account = $this->global_data['account'];
            if ('tuzi' == $account) {
                $list = \think\Db::table('v_finance_recharge')->paginate(20);
            } else {
                $list = \think\Db::table('v_finance_recharge')->where(['account' => $account])->paginate(20);
            }
        }
        return view('', ['list' => $list,'search'=>$searchData]);
    }

    public function doRechargeSubmit() {
        $data = [
            'account' => 'tuzi',
            'out_trade_no' => date('YmdHis'),
            'amount' => 1,
            'pay_channel' => 'wxjsapi',
            'user_id' => 1,
            'remark' => 'test',
            'status' => 0,
        ];
        \app\cpmjagent\model\finance\RechargeModel::create($data);
        $sqlstmt = 'insert into t_finance_recharge (account, out_trade_no, amount, pay_channel, user_id, remark, status) values (:account, :out_trade_no, :amount, :pay_channel, :user_id, :remark, 1)';
        return 'ok';
    }

    public function doRechargeAudit() {

        \app\cpmjagent\model\finance\RechargeModel::update(['status' => 1], ['out_trade_no' => '20170706221351']);
        $sqlstmt = 'update t_finance_recharge set status=1 where out_trade_no=@out_trade_no';
        return 'ok';
    }

}
